package itsm.isperp.module.service.incident;

import java.util.List;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.web.request.JqGridFilterRule;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.incident.IcdMajorChat;
import itsm.isperp.module.repository.incident.IcdMajorChatMapper;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

/**
 * 服务
 * 
 * @author lizx
 * @date 2016-11-28 09:29
 */
@Service
public class IcdMajorChatService extends BaseService<IcdMajorChat> {

	@Autowired
	protected IcdMajorChatMapper icdMajorChatMapper;

	@Override
	public IcdMajorChatMapper getRepository() {
		return this.icdMajorChatMapper;
	}

	public List<IcdMajorChat> findByIncidentId(String incidentId,int lastInt) {
		IcdMajorChatService icdMajorChatService = ContextHolder
				.getSpringBean("icdMajorChatService");
		JqGridRequest req = new JqGridRequest();
		req.isPageable(false);
		req.addFilterRule("incidentId", JqGridFilterRuleOp.eq, incidentId);
		req.setSort("sendTime", Direction.ASC);

		if (lastInt!=0) {

			req.setSearchString(" send_ord > " + lastInt + "");
		}

		return icdMajorChatService.findAll(req);
	}

}
